Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(mypy): enable more mypy codes #3817

Merged
merged 1 commit into from
Oct 16, 2024
Merged

chore(mypy): enable more mypy codes #3817

merged 1 commit into from
Oct 16, 2024

Conversation

sobolevn
Copy link
Member

I've enabled more mypy codes:

  • local_partial_types is needed for compat between mypy and dmypy
  • truthy-iterable guards us from this problem:
>>> class I:
...     def __iter__(self):
...         return iter([])
...         
>>> bool(I())
True

We had this problem in three places:

» pdm run mypy
litestar/middleware/logging.py:106: error: Member "response_log_fields" has type "Iterable[Literal['status_code', 'headers', 'body', 'cookies']]" which can always be true in boolean context. Consider using "Collection[Literal['status_code', 'headers', 'body', 'cookies']]" instead.  [truthy-iterable]
litestar/middleware/logging.py:109: error: Member "request_log_fields" has type "Iterable[Literal['path', 'method', 'content_type', 'headers', 'cookies', 'query', 'path_params', 'body', 'scheme', 'client']]" which can always be true in boolean context. Consider using "Collection[Literal['path', 'method', 'content_type', 'headers', 'cookies', 'query', 'path_params', 'body', 'scheme', 'client']]" instead.  [truthy-iterable]
litestar/testing/websocket_test_session.py:81: error: "headers" has type "Iterable[Tuple[bytes, bytes]]" which can always be true in boolean context. Consider using "Collection[Tuple[bytes, bytes]]" instead.  [truthy-iterable]
Found 3 errors in 2 files (checked 758 source files)

So, I fixes all of them. response_log_fields and request_log_fields where indeed not just Iterables but Collections

The other one I just ignored, because it is a test code.

  • unused-awaitable has 0 cases
  • redundant-self has 0 cases

Docs on error codes: https://mypy.readthedocs.io/en/stable/error_code_list2.html
Docs on local_partial_types: https://mypy.readthedocs.io/en/stable/config_file.html#confval-local_partial_types

@sobolevn sobolevn requested review from a team as code owners October 16, 2024 13:37
@github-actions github-actions bot added area/dependencies This PR involves changes to the dependencies area/middleware This PR involves changes to the middleware area/testing size: small pr/external Triage Required 🏥 This requires triage labels Oct 16, 2024
@sobolevn
Copy link
Member Author

Later I can enable more codes, but they require fixes / changes.

@provinzkraut provinzkraut enabled auto-merge (squash) October 16, 2024 13:42
Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.39%. Comparing base (236cfa3) to head (d20b0f1).
Report is 1 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #3817   +/-   ##
=======================================
  Coverage   98.39%   98.39%           
=======================================
  Files         332      332           
  Lines       15472    15472           
  Branches     1703     1703           
=======================================
  Hits        15224    15224           
  Misses        113      113           
  Partials      135      135           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@provinzkraut provinzkraut merged commit a7cd193 into main Oct 16, 2024
24 checks passed
@provinzkraut provinzkraut deleted the mypy-extra-codes branch October 16, 2024 13:42
Copy link

sonarcloud bot commented Oct 16, 2024

Copy link

Documentation preview will be available shortly at https://litestar-org.github.io/litestar-docs-preview/3817

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/dependencies This PR involves changes to the dependencies area/middleware This PR involves changes to the middleware area/testing pr/external size: small Triage Required 🏥 This requires triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants